//
//  PinViewController.m
//  A段
//
//  Created by 月月 on 15/4/13.
//  Copyright (c) 2015年 dllo. All rights reserved.
//

#import "PinViewController.h"
#import "UIImageView+WebCache.h"
#import "LinkViewController.h"


@interface PinViewController ()<UIScrollViewDelegate>
{
    UIScrollView *_scroll;
}

@end

@implementation PinViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.automaticallyAdjustsScrollViewInsets = NO;
    
    self.navigationItem.title = self.name;
    
    [self.view setBackgroundColor:[UIColor whiteColor]];
    
    [self createScroll];
    
    
    
}

-(void)createScroll
{
    _scroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 64, self.view.frame.size.width, self.view.frame.size.height - 64 - 44)];
//    // 设置滚动范围大小 (上下不滚动,左右滚动)
//    [_scroll setContentSize:CGSizeMake(_scroll.frame.size.width * 13, _scroll.frame.size.height)];
    [_scroll setBounces:NO];
    // 整页滚动图片
    [_scroll setPagingEnabled:YES];
    
    //    _scroll.zoomScale = 2.0f;
    _scroll.delegate = self;
    [self.view addSubview:_scroll];
    [_scroll release];
    
    
    [self createImage];
    
    [self createlabel];
    
    [self createcontentLabel];
    
}

-(void)createImage
{
    UIImageView *image = [[[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 150, 200)] autorelease];
    [image sd_setImageWithURL:[self.dic objectForKey:@"cover_thumb"]];
    [_scroll addSubview:image];
    
}

-(void)createlabel
{
    UILabel *label = [[[UILabel alloc] initWithFrame:CGRectMake(150, 0, _scroll.frame.size.width - 150, 200)] autorelease];
    [_scroll addSubview:label];
    label.numberOfLines = 0;
    label.text = [self.dic objectForKey:@"summary"];
}

-(void)createcontentLabel
{
    NSString *connect1 = [self.dic objectForKey:@"content"];

    NSDictionary *dit = @{NSFontAttributeName:[UIFont systemFontOfSize:17.0f]};
    CGRect rect = [connect1 boundingRectWithSize:CGSizeMake(_scroll.frame.size.width - 20, 1000000) options:NSStringDrawingUsesLineFragmentOrigin attributes:dit context:nil];
    UILabel *content = [[[UILabel alloc] initWithFrame:CGRectMake(10, 200, _scroll.frame.size.width - 20 , rect.size.height )] autorelease];
    content.numberOfLines = 0;
    content.text = connect1;
    [_scroll addSubview:content];
    _scroll.contentSize = CGSizeMake(0, rect.size.height +  300);
    
    
    UIButton *link = [[[UIButton alloc] initWithFrame:CGRectMake(30, rect.size.height + 220 + 20 , 300, 40)] autorelease];
    [_scroll addSubview:link];
    [link setBackgroundColor:[UIColor grayColor]];
   [link setTitle:[self.dic objectForKey:@"title"] forState:UIControlStateNormal];
    [link addTarget:self action:@selector(linkAction:) forControlEvents:UIControlEventTouchUpInside];
    
}

-(void)linkAction:(id)sender
{
    LinkViewController *link = [[[LinkViewController alloc] init] autorelease];
    link.dic = self.dic;
    [self.navigationController pushViewController:link animated:YES];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
